package consultan.vanke.com.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.viewpager.widget.ViewPager;

import com.androidkun.xtablayout.XTabLayout;

import java.util.ArrayList;

import butterknife.BindView;
import consultan.vanke.com.R;
import consultan.vanke.com.adapter.BaseFragmentAdapter;
import consultan.vanke.com.constant.ConstantLibrary;
import consultan.vanke.com.utils.SimpleToolbar;

import static com.bytedance.sdk.account.open.aweme.utils.ViewUtils.getStatusBarHeight;
import static consultan.vanke.com.utils.StatusBarUtil.setPaddingTop;
import static consultan.vanke.com.utils.StatusBarUtil.setRootView;


public class DtCjFragment extends BaseFragment {
    @BindView(R.id.tablayout)
    XTabLayout tablayout;
    @BindView(R.id.vp_view)
    ViewPager vpView;
    @BindView(R.id.img_bottom)
    ImageView imgBottom;
    @BindView(R.id.linerar_bottom)
    LinearLayout linerarBottom;
    @BindView(R.id.linear_bottom)
    LinearLayout linearBottom;
    private View inflate;
    private boolean isfristshow = true;
    @BindView(R.id.simple_toolbar)
    SimpleToolbar simpleToolbar;
    @BindView(R.id.simple_toolbar_main)
    ConstraintLayout simpleToolbarMain;
    private ArrayList<String> titles;
    private ArrayList<BaseFragment> fragments;
    private int deliverType;

    public DtCjFragment(int deliverType) {
        this.deliverType = deliverType;
    }

    @Override
    protected void initViews() {
        simpleToolbar.setMainBg(getResources().getColor(R.color.white_color));
        simpleToolbar.setRightTitleText("编辑");
        simpleToolbar.setRightTitleColor(getResources().getColor(R.color.color_617DF6));
        simpleToolbar.setRightTitleAginClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (simpleToolbar.getRightTitleText().equalsIgnoreCase("编辑")) {
                    simpleToolbar.setRightTitleText("删除");
                    linerarBottom.setVisibility(View.VISIBLE);
                    imgBottom.setVisibility(View.GONE);
                } else {
                    simpleToolbar.setRightTitleText("编辑");
                    linerarBottom.setVisibility(View.GONE);
                    imgBottom.setVisibility(View.VISIBLE);
                }
            }
        });
        if (deliverType == ConstantLibrary.DONGTAIA1) {
            simpleToolbar.setMainTitle("静态场景");
        } else if (deliverType == ConstantLibrary.DONGTAIA2) {
            simpleToolbar.setMainTitle("动态场景");
        } else {
            simpleToolbar.setMainTitle("自定义场景");
        }
    }

    @Override
    protected void initDatas() {
        titles = new ArrayList<>();
        titles.add("森林类");
        titles.add("雪山类");
        titles.add("水边类");
        titles.add("星空类");
        titles.add("星空类");
        titles.add("星空类");
        titles.add("星空类");
        fragments = new ArrayList<>();
        fragments.add(new ShopMusicFragment());
        fragments.add(new ShopMusicFragment());
        fragments.add(new ShopMusicFragment());
        fragments.add(new ShopMusicFragment());
        fragments.add(new ShopMusicFragment());
        fragments.add(new ShopMusicFragment());
        fragments.add(new ShopMusicFragment());
        BaseFragmentAdapter adapter = new BaseFragmentAdapter(getChildFragmentManager(), fragments, titles);
        vpView.setAdapter(adapter);
        vpView.setOffscreenPageLimit(ConstantLibrary.VIEWPAGERLIMIT);
        tablayout.setupWithViewPager(vpView);
    }

    @Override
    protected void initEvents() {
        simpleToolbar.setLeftTitleClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pop();
            }
        });
    }

    @Override
    protected View initContentView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        inflate = View.inflate(_mActivity, R.layout.dt_cj_fragment, null);
        return inflate;
    }

    @Override
    public void onSupportVisible() {
        super.onSupportVisible();
        ViewGroup decorView = (ViewGroup) _mActivity.getWindow().getDecorView();
        View fakeStatusBarView = new View(_mActivity);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(_mActivity) + 3);
        fakeStatusBarView.setLayoutParams(params);
        fakeStatusBarView.setBackground(getResources().getDrawable(R.drawable.bg_white));
        fakeStatusBarView.setId(android.R.id.custom);
        decorView.addView(fakeStatusBarView);
        setRootView(_mActivity, false);
        if (isfristshow) {
            setPaddingTop(_mActivity, simpleToolbar);
            isfristshow = false;
        }
        setStatusBarColors(getResources().getColor(R.color.white_color), true);
    }

}
